package com.custom;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.Utils.CustomViewBinder;
import com.mode.SelectedMenuObj;

public class ClassListViewWidget extends LinearLayout {

	int mWidth,mHeight;
	List<SelectedMenuObj> selectedMenuList;
	ArrayList<HashMap<String, Object>> hashList;
	TextView titleTextView;
	public ListView listView;
	
	public ClassListViewWidget(Context context,List<SelectedMenuObj> menulist,ArrayList<HashMap<String, Object>> hList,
			String strtitle) {
		super(context);
		// TODO Auto-generated constructor stub
		this.setOrientation(LinearLayout.VERTICAL);
//		this.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
		
		selectedMenuList=menulist;
		hashList=hList;
//		simpleAdapter=sAdapter;
		
		titleTextView=new TextView(context);
		titleTextView.setWidth(200);
		titleTextView.setTextColor(Color.RED);
		titleTextView.setTextSize(25);
		titleTextView.setText(strtitle);
		this.addView(titleTextView);
		
		LinearLayout line=new LinearLayout(context);
		line.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,3));
		line.setBackgroundColor(Color.RED);
		this.addView(line);
		
		listView=new ListView(context);
		this.addView(listView);
//		simpleAdapter.setViewBinder(new CustomViewBinder());
//		listView.setAdapter(simpleAdapter);
//		setListViewHeight(listView);
	}
	public void setListViewHeight(ListView lv) {
        ListAdapter la = lv.getAdapter();
        if(null == la) {
            return;
        }
        // calculate height of all items.
        int h = 0;
        final int cnt = la.getCount();
        for(int i=0; i<cnt; i++) {
            View item = la.getView(i, null, lv);
            item.measure(0, 0);
            h += item.getMeasuredHeight();
        }
        // reset ListView height
        ViewGroup.LayoutParams lp = lv.getLayoutParams();
        lp.height = h + (lv.getDividerHeight() * (cnt - 1));
        lp.width=android.view.ViewGroup.LayoutParams.FILL_PARENT;
        lv.setLayoutParams(lp);
    }
	public boolean isEmpty()
	{
		if(hashList.size()<=0)
			return true;
		else {
			return false;
		}
	}
	
	public int getmWidth() {
		return mWidth;
	}
	public void setmWidth(int mWidth) {
		this.mWidth = mWidth;
	}
	public int getmHeight() {
		return mHeight;
	}
	public void setmHeight(int mHeight) {
		this.mHeight = mHeight;
	}
	public List<SelectedMenuObj> getSelectedMenuList() {
		return selectedMenuList;
	}
	public void setSelectedMenuList(List<SelectedMenuObj> selectedMenuList) {
		this.selectedMenuList = selectedMenuList;
	}
	public ArrayList<HashMap<String, Object>> getHashList() {
		return hashList;
	}
	public void setHashList(ArrayList<HashMap<String, Object>> hashList) {
		this.hashList = hashList;
	}
	public TextView getTitleTextView() {
		return titleTextView;
	}
	public void setTitleTextView(TextView titleTextView) {
		this.titleTextView = titleTextView;
	}
	public ListView getListView() {
		return listView;
	}
	public void setListView(ListView listView) {
		this.listView = listView;
	}

}
